package com.cookbook.cookbookservice.controller;

import com.cookbook.cookbookservice.util.Response;
import com.cookbook.cookbookservice.util.TencentCOS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss")
public class OssController {
    private Logger logger = LoggerFactory.getLogger(OssController.class);

    /**
     * oss 上传
     *
     * @param image
     * @return
     */
    @PostMapping("uploadImage")
    private Response uploadImage(MultipartFile image) {
        TencentCOS tencentCOS = new TencentCOS();
        try {
            tencentCOS.uploadCOS(image);
            return Response.success();
        } catch (Exception e) {
            logger.error("上传失败", e);
            return Response.error(5000, "上传失败");
        }
    }
}
